

<template>
<table>

        <tr>
            <th>房型名称</th>
            <th>
                <input type="text" v-model="tianjia1.rType_Name"> 
            </th>
        </tr>

        
        <tr>
            <th>门市价</th>
            <th>
                <input type="text" v-model="tianjia1.rtype_Price"> 
            </th>
        </tr>

        
        <tr>
            <th>押金</th>
            <th>
                <input type="text" v-model="tianjia1.rtype_Deposit"> 
            </th>
        </tr>

        
        <tr>
            <th>面积</th>
            <th>
                <input type="text" v-model="tianjia1.rtype_Size"> 
            </th>
        </tr>

        
        <tr>
            <th>可住人数</th>
            <th>
                <input type="text" v-model="tianjia1.rtype_num"> 
            </th>
        </tr>

        
        <tr>
            <th>可否加床</th>
            <th>
                <input type="radio" :value="1" v-model="tianjia1.rtype_AddBed"> 是 
                <input type="radio" :value="0" v-model="tianjia1.rtype_AddBed"> 否
            </th>
        </tr>

        
        <tr>
            <th>房型图片</th>
            <th>
                <img :src="tianjia1.dtype_Img" style="height: 100px; width: 100px;">
               <input type="file" @change="Img">
            </th>
        </tr>

        
        <tr>
            <th>房型介绍</th>
            <th>
                <input type="text" v-model="tianjia1.rtype_Info"> 
            </th>
        </tr>

        
        <tr>
            <th>房型投放</th>
            <th>
                <input type="radio" :value="1" v-model="tianjia1.rtype_Satate"> 投放 
                <input type="radio" :value="0" v-model="tianjia1.rtype_Satate"> 暂缓
            </th>
        </tr>


    
        <tr>
            <th></th>
            <th>
             <button @click="Tianjia"> 添加</button>
            </th>
        </tr>

</table>
</template>




<script  setup lang="ts">

import axios from 'axios';
import {ref} from 'vue';

const tianjia1=ref({
    
  "rType_Name": "string",
  "rtype_Price": 0,
  "rtype_Deposit": 0,
  "rtype_Size": 0,
  "rtype_num": 0,
  "rtype_AddBed": "string",
  "dtype_Img": "string",
  "rtype_Info": "string",
  "rtype_Satate": "string"
})


const Img =(e:any)=>{

        var a = e.target.files[0];
        var b =  new FormData();

        b.append('images',a)

        axios.post('https://localhost:7197/api/UpFile/UpFile',b).then(res=>{

            tianjia1.value.dtype_Img =res.data

        })

}



const Tianjia=()=>{

    console.log(tianjia1.value)

    tianjia1.value.rtype_Satate=tianjia1.value.rtype_Satate.toString();
    tianjia1.value.rtype_AddBed=tianjia1.value.rtype_AddBed.toString();
    axios.post('https://localhost:7197/api/RoomType/AddRommType',tianjia1.value).then(res=>{

        if(res.data>0)
    {
        alert('添加成功')
    }
    else
    {
        alert('添加失败')
    }
    })


}

</script>
